package ru.evga.gwt.lib.common.client.place;

import java.util.HashMap;
import java.util.Map;

public class PlaceParamMap
{
    private final Map<String, String> m_map;
    
    public PlaceParamMap()
    {
        m_map = new HashMap<String, String>();
    }
 
    public static PlaceParamMap makePlaceParamMap(PlaceImpl place)
    {
        PlaceParamMap map = new PlaceParamMap();
        String [] pairs = place.getToken().split(PlaceImpl.TOKEN_SEPARATOR);
        for(int i = 0; i < pairs.length; i++)
        {
            String [] keyAndValue = pairs[i].split(PlaceImpl.TOKEN_PAIR_SEPARATOR);
            map.put(keyAndValue[0], keyAndValue.length > 1 ? keyAndValue[1] : null);
        }
        return map;
    }

    
    public PlaceParamMap put(String key, String value)
    {
        //TODO add unique test
        m_map.put(key, value);
        return this;
    }
    
    public String get(String key)
    {
        return m_map.get(key);
    }
    
   
}
